<?php

namespace app\controller;

class AdminMenu
{
    public static function read()
    {
        return get_menu_cache();
    }

    public static function queryTop(\app\model\AdminMenu $model)
    {
        return $model->queryTop();
    }

    public static function getAllMenuData(\app\model\AdminMenu $model)
    {
        return $model->getAllMenuData();
    }

    public function addTopMenu(\app\model\AdminMenu $model)
    {
        $model->menuName = input('param.menu_name');
        $model->menuIcon = input('param.menu_icon');
        record_log('增加了 顶级菜单 '.input('param.menu_name'));
        return boolval($model->addTopMenu()) == true ?
            json(200) : json(500);
    }

    public function deleteMenu(\app\model\AdminMenu $model)
    {
        $model->id = input('param.id');
        record_log('删除了 ID 编号为 '.input('param.id').' 的菜单');
        return boolval($model->deleteMenu()) == true ?
            json(200) : json(500);
    }

    public static function queryMenuData(\app\model\AdminMenu $model, int $id)
    {
        $model->id = $id;
        return $model->queryMenuData();
    }

    public function editMenuData(\app\model\AdminMenu $model)
    {
        $model->id = input('param.id');
        $model->menuName = input('param.menu_name');
        $model->menuIcon = input('param.menu_icon');
        $model->menuUrl = input('param.menu_url');
        record_log('修改菜单编号 ID 为 '.input('param.id').' 的信息');
        return boolval($model->editMenuData()) == true ?
            json(200) : json(500);
    }

    public function addSonMenu(\app\model\AdminMenu $model)
    {
        $model->topId = input('param.top_id');
        $model->menuName = input('param.menu_name');
        $model->menuUrl = input('param.menu_url');
        record_log('添加子菜单 '.input('param.menu_name'));
        return boolval($model->addSonMenu()) == true ?
            json(200) : json(500);
    }
}